<!-- 单日未出 -->
<template>
	<view class="visite">
	<model-page>
	<Search :searchResult="serchText">
		<view  @click="cancelSearch">
			取消
		</view>
	</Search>
	<view class="tables">
		<Table 
		:headList="headList" 
		:tableData="tableData" 
		:total="total" 
		v-model:pageNum="postData.pageNum"
		:pageSize="postData.pageSize"
		 @checkPage="checkPage"
		:stateList="stateList"
		></Table>
	</view>
	</model-page>
	</view>
</template>

<script setup>
import {ref,nextTick} from 'vue'
import Search from '@/component/Search.vue'
import Table from '@/component/Table.vue'
import {listVisitForGuard} from '@/api/visite.js'
import {onLoad,onShow} from '@dcloudio/uni-app'
const headList = ref([
	{
	title:"房间",
	props:"buildRoomNum",
	width:"18%"	
	},
	{
	title:"老人名",
	props:"elderName",
	width:"18%"	
	},
	{
	title:"申请时间",
	props:"createTime",
	width:"34%"	
	},
	{
	title:"操作",
	props:"visiteleaveStatus",
	width:"20%"	
	}
])
const stateList = [{
	id:"1",
	label:"查看详情",
	color:"#2778FF",
	path:"/packageVisite/pages/mwVisiteInfo/mwVisiteInfo"
}
]
const serchText = ref("")
const cancelSearch = ()=>{
	serchText.value = ""
	delete postData.value.elderId
     getVisiteList()
}
// 切换分页
const checkPage = (type)=>{
	getVisiteList()
}
//获取探望列表
const tableData = ref([])
const postData =ref({
	pageNum:1,
	pageSize:10,
}) 
const total = ref(0)
const getVisiteList = async()=>{
	try{
		const {code,data:res} = await listVisitForGuard(postData.value)
		if(code === 200){
			total.value = res.total
			tableData.value = res.list.map(val=>{
				return Object.assign(val,{visiteleaveStatus:"1"})
			})
		}
	}catch(e){
		//TODO handle the exception
		return Promise.reject(e)
	}
}
onShow(()=>{
	getVisiteList()
})
onLoad(()=>{
	uni.$on("undateElderId",(option)=>{
		const {type,searchResult} = option
		serchText.value = searchResult || ""
		delete postData.value.reviewStatus
		postData.value.pageNum = 1
		postData.value.elderId = type
		getVisiteList()
	})
})
</script>

<style lang="less" scoped>
	.visite{
		.tables{
			margin-top: 45rpx;
		}
	}
</style>